function getResults()
{
	clear();
	
	var form = document.forms[0];
	form.submitButton.disabled = true;
	var language = $F(form['selLanguage']);
	var query = $F(form['textQuery']);
	
	if(query.blank() ||
		query == 'Enter search query here.') {
		form.submitButton.disabled = false;
		return error('Please enter a query string.');
	}
	
	
	var data = 'selLanguage='+escape(language);
	data += '&textQuery='+escape(query);
	
	//send request
	new Ajax.Request('/ExecuteQueryServlet.an', 
	{
		method:'post',
		postBody:data,
		onFailure: function(){ alert('Error fetching results!!'); form.submitButton.disabled = false;},
		onSuccess: function(transport){  $('searchResults').innerHTML = transport.responseText; form.submitButton.disabled = false; }
		
	});
	
}

function openFile(file)
{
	url = "/GetCodeHtmlServlet.an?file=" + file + "&rand=" + Math.random();
	var sourceWindow = window.open(url, file, "menubar=0,resizable=1,width=800,height=600,status=1,toolbars=0,scrollbars=1");
	sourceWindow.focus(); 
}


function addFieldToQuery()
{
	initQuery()

	var form = document.forms[0];
	var field = $F(form['selField']);
	var fieldValue = $F(form['txtField']);
	var query = $F(form['textQuery']);
	
	if(!query.blank()) {
		$(form['textQuery']).value += ' ';
	}
	
	$(form['textQuery']).value += (field + ': ' + fieldValue + ' ');
}

function addClauseToQuery()
{
	initQuery();

	var form = document.forms[0];
	var clause = $F(form['selClause']);
	var query = $F(form['textQuery']);
	
	if(query.blank() || query == '') {
		clearQuery();
		return error('Query string cannot start with a clause.');
	}
	
	$(form['textQuery']).value += (' ' + clause + ' ');
}


function error(msg)
{
	$('searchResults').update(msg).setStyle( {color: 'red'} ).pulsate();
	return -1;
}

function clear()
{
	$('searchResults').update('').setStyle({color: '#000000'});
	return 0;
}

function clearQuery()
{
	var form = document.forms[0];
	var txtQuery = $(form['textQuery']);
	
	txtQuery.style.color = '#929da1';
	txtQuery.value = 'Enter search query here.';
}

function initQuery()
{
	var form = document.forms[0];
	var txtQuery = $(form['textQuery']);
	
	txtQuery.style.color = '#000000';
	if (txtQuery.value.blank() ||
		txtQuery.value == 'Enter search query here.' ) {
		txtQuery.value = '';
	}
	
	return 0;
}